<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>sndloop</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="sliderKawai.html" title="sliderKawai" />
    <link rel="next" href="sndwarp.html" title="sndwarp" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">sndloop</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="sliderKawai.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="sndwarp.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="sndloop"></a>
      <div class="titlepage"></div>
      <a id="Indexsndloop" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">sndloop</span>
        </h2>
        <p>sndloop — 
      A sound looper with pitch control.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp149133728"></a>
        <h2>Description</h2>
        <p>
   This opcode records input audio and plays it back in a loop with user-defined
   duration and crossfade time. It also allows the pitch of the loop to be controlled,
   including reversed playback.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp149203424"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">asig, krec <span class="command"><strong>sndloop</strong></span> ain, kpitch, ktrig, idur, ifad</pre>
      </div>
      <div class="refsect1">
        <a id="idp149205648"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>idur </em></span> -- loop duration in seconds
    </p>
        <p>
      <span class="emphasis"><em>ifad </em></span> -- crossfade duration in seconds
    </p>
      </div>
      <div class="refsect1">
        <a id="idp149208144"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>asig</em></span> -- output sig
    </p>
        <p>
      <span class="emphasis"><em>krec</em></span> -- 'rec on' signal, 1 when recording, 0 otherwise
    </p>
        <p>
      <span class="emphasis"><em>kpitch</em></span> -- pitch control (transposition ratio); negative values play the loop back in reverse
    </p>
        <p>
      <span class="emphasis"><em>ktrig</em></span> -- trigger signal: when 0, processing is bypassed. When switched on (ktrig &gt;= 1),
      the opcode starts recording until the loop memory is full. It then plays
      the looped sound until it is switched off again (ktrig = 0). Another recording
      can start again with ktrig &gt;= 1.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp149212624"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the sndloop opcode. It uses the file <a class="ulink" href="examples/sndloop.csd" target="_top"><em class="citetitle">sndloop.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp149214448"></a>
          <p class="title">
            <strong>Example 825. Example of the sndloop opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac      <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o sndloop.wav -W  ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100 
<span class="ohdr">ksmps</span> <span class="op">=</span> 32 
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1 
<span class="ohdr">nchnls</span> <span class="op">=</span> 2

<span class="oblock">instr</span> 1

itrig  <span class="op">=</span> p4
asig   <span class="opc">diskin2</span> "beats.wav", 1, 0, 1		<span class="comment">;get the signal in, loop it</span>
ktrig  <span class="opc">line</span> 0, itrig, 1				<span class="comment">;when to trigger signal = p4</span>
kpitch <span class="opc">line</span> 1.2, p3, .5				<span class="comment">;vary pitch of recorded signal</span>
aout,krec <span class="opc">sndloop</span> asig, kpitch, ktrig, .4, 0.05	<span class="comment">;rec starts at p4 sec, for .4 secs and 0.05 crossfade</span>
       <span class="opc">printk2</span> krec               	  	<span class="comment">; prints the recording signal</span>
       <span class="opc">outs</span>    aout, aout

<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="stamnt">i</span>1 0 5 .5	<span class="comment">;trigger in seconds (=p4)</span>
<span class="stamnt">i</span>1 + 5 .8
<span class="stamnt">i</span>1 + 10 1.2

<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
        <p>
      The example above shows the basic operation of sndloop. Pitch can
      be controlled at the k-rate, recording is started as soon as the
      trigger value is &gt;= 1. Recording can be restarted by making the trigger 0 and
      then 1 again.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp149219392"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Victor Lazzarini</td>
          </tr>
          <tr>
            <td>April 2005 </td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in Version 5.00</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="sliderKawai.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="sndwarp.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">sliderKawai </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> sndwarp</td>
        </tr>
      </table>
    </div>
  </body>
</html>
